<script setup lang="ts">
import { useRouter } from 'vue-router'
import { useLogin } from './hooks/useLogin'
import { useLoginFormState } from './hooks/useLoginFormState'
import { RollbackOutlined } from '@ant-design/icons-vue'

const router = useRouter()
const { formState } = useLoginFormState()
const { loading, onFinish } = useLogin(router.currentRoute.value.query.redirect)
function onClickBack() {
  router.replace({ name: 'Home' })
}
</script>

<template>
  <div class="form-continer">
    <ASpin :spinning="loading">
      <AButton class="back-btn" type="text" @click="onClickBack"><RollbackOutlined /></AButton>
      <div class="login-title">登录</div>
      <AForm :model="formState" autocomplete="off" layout="vertical" @finish="onFinish">
        <AFormItem
          label="用户名"
          name="userName"
          :rules="[{ required: true, message: '请输入用户名', trigger: 'blur' }]"
        >
          <AInput v-model:value="formState.userName" class="form-item form-input" />
        </AFormItem>
        <AFormItem
          label="密码"
          name="password"
          :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]"
        >
          <AInputPassword v-model:value="formState.password" class="form-item form-input" />
        </AFormItem>
        <AFormItem style="margin-top: 28px">
          <AButton class="form-item submit-btn" block html-type="submit">登录</AButton>
        </AFormItem>
      </AForm>
    </ASpin>
  </div>
</template>

<style lang="less" scoped>
.form-continer {
  background-color: white;
  border-radius: 12px;
  width: 80%;
  padding: 20px 32px 32px;
  display: flex;
  flex-direction: column;

  .back-btn {
    position: absolute;
    top: 14px;
    right: 0;
    padding: 0;
    width: 32px;
  }

  .login-title {
    color: #516473;
    font-size: 38px;
    font-weight: 800;
    margin-bottom: 8px;
    text-align: center;
  }

  .form-item {
    border-radius: 20px;
  }

  // :deep(.ant-form-item) {
  //   margin-bottom: 4px;
  // }
  :deep(.ant-form-item-label) {
    padding-bottom: 0;
  }
  :deep(.ant-form-item-label > label) {
    color: #536674;
  }
  :deep(.ant-input-affix-wrapper-focused) {
    border-color: #3b4859;
    box-shadow: 0 0 0 2px #3b485927;
  }

  .form-input {
    &:hover {
      border-color: #3b4859;
    }
    &:focus {
      border-color: #3b4859;
      box-shadow: 0 0 0 2px #3b485927;
    }
  }

  .submit-btn {
    margin-top: 8px;
    background-color: #3b4859;
    color: white;
    &:hover {
      border-color: #3b4859;
    }
  }
}
</style>
